package com.xinhe.web.controller;

import com.xinhe.web.common.Result;
import com.xinhe.web.request.ShopCartModel;
import com.xinhe.web.service.ShopcartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Set;

@Api(value = "购物车", tags = {"购物车"})
@RestController
@RequestMapping(value = {"/shopcart"}, produces = {"application/json;charset=UTF-8"})

public class ShopCartController {
    @Resource
    private ShopcartService shopcartService;

    @ApiOperation(httpMethod = "POST", value = "添加购物车 选中一次就调用一次")
    @RequestMapping({"/saveShopcart"})
    public Result saveShopcart(@Valid @RequestBody ShopCartModel model) {
        this.shopcartService.saveShopcart(model);
        return Result.ok();
    }

    @ApiOperation(httpMethod = "POST", value = "修改购物车数量")
    @RequestMapping({"/saveShopcartAmount"})
    public Result saveShopcartAmount(Integer amount,Long orderItemId) {
        return this.shopcartService.saveShopcartAmount(amount,orderItemId);
    }

    @ApiOperation(httpMethod = "POST", value = "添加立即购买", notes = "返回保存标识，供提交订单界面查询使用")
    @RequestMapping({"/saveBuyNow"})
    public Result saveBuyNow(@Valid @RequestBody ShopCartModel model) {
        return this.shopcartService.saveBuyNow(model);
    }

    @ApiOperation(httpMethod = "GET", value = "查询购物车商品")
    @RequestMapping({"/findShopcart"})
    public Result findShopcart() {
        return this.shopcartService.findShopcart();
    }

    @ApiOperation(httpMethod = "POST", value = "查询订单提交信息")
    @RequestMapping({"/findForSubmit"})
    public Result findForSubmit(Set<Long> orderItemIds) {
        return this.shopcartService.findForSubmit(orderItemIds);
    }

    @ApiOperation(httpMethod = "GET", value = "查询购物车数量")
    @RequestMapping({"/countShopcart"})
    public Result countShopcart() {
        return this.shopcartService.countShopcart();
    }

    @ApiOperation(httpMethod = "POST", value = "删除购物车")
    @RequestMapping({"/deleteShopcart"})
    public Result deleteShopcart(Set<Long> orderItemIds) {
        this.shopcartService.deleteShopcart(orderItemIds);
        return Result.ok();
    }


}
